﻿//using Microsoft.AspNetCore.Http;
//using Microsoft.AspNetCore.Mvc;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
//using System.Reflection;
//using NoORM.Core.Contract;

//namespace Restsql.Api.Controllers
//{
//    [Route("[controller]/{className}")]
//    [ApiController]
//    public class DeveloperController : ControllerBase
//    {
//        /// <summary>
//        /// 开发者get请求
//        /// </summary>
//        /// <param name="className">类名</param>
//        /// <param name="query">查询字符串</param>
//        /// <param name="token">header中的票据</param>
//        /// <param name="custom">header中的数据</param>
//        /// <returns></returns>
//        [HttpGet]
//        public JsonResult Get(string className, [FromQuery]Dictionary<string,string> query, [FromHeader] string token,[FromHeader] string custom)
//        {
//            ApiData<object> api = new ApiData<object>();
//            api.ServerReceiveTime = DateTime.Now;
//            try
//            {
//                string classFullName = $"Restsql.Developer.Controllers.{className}";
//                Type serviceType = Type.GetType($"{classFullName},Restsql.Developer");
//                object serverInstance = DeveloperServiceProvider.ApplicationServices.GetService(serviceType);
//                CustomRequest request = new CustomRequest()
//                {
//                    Query = query,
//                    Body = null,
//                    HeaderToken = token,
//                    HeaderCustomData = custom
//                };
//                object[] args = new object[] { request };
//                object result = serviceType.InvokeMember("Get", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, serverInstance, args);
//                api.Success = true;
//                api.Data = result;
//            }catch(Exception ex)
//            {
//                api.Success = false;
//                api.Message = ex.Message;
//            }
//            api.ServerSendTime = DateTime.Now;
//            return new JsonResult(api);
//        }

//        /// <summary>
//        /// 开发者post请求
//        /// </summary>
//        /// <param name="className">类名</param>
//        /// <param name="body">post数据</param>
//        /// <param name="token">header中的票据</param>
//        /// <param name="custom">header中的数据</param>
//        /// <returns></returns>
//        [HttpPost]
//        public JsonResult Post(string className,Dictionary<string,object> body, [FromHeader] string token, [FromHeader] string custom)
//        {
//            ApiData<object> api = new ApiData<object>();
//            api.ServerReceiveTime = DateTime.Now;
//            try
//            {
//                string classFullName = $"Restsql.Developer.Controllers.{className}";
//                Type serviceType = Type.GetType($"{classFullName},Restsql.Developer");
//                object serverInstance = DeveloperServiceProvider.ApplicationServices.GetService(serviceType);
//                CustomRequest request = new CustomRequest()
//                {
//                    Body = body,
//                    HeaderToken = token,
//                    HeaderCustomData = custom
//                };
//                object[] args = new object[] { request };
//                object result = serviceType.InvokeMember("Post", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, serverInstance, args);
//                api.Success = true;
//                api.Data = result;
//            }
//            catch (Exception ex)
//            {
//                api.Success = false;
//                api.Message = ex.Message;
//            }
//            api.ServerSendTime = DateTime.Now;
//            return new JsonResult(api);
//        }     
//    }
//}
